import React from "react";
import { Form, Input, Button, TextArea, Toast } from "antd-mobile";
import axios from "axios";
import { useNavigate } from "react-router-dom";
export default function SetMy() {
  const navigate = useNavigate();
  const onFinish = (values) => {
    console.log(values, "v");
    axios.post(`http://localhost:3004/users`, {
      username: values.username,
      password: values.password,
      name: values.name,
      phone: values.phone,
      city: values.city,
      job_unit: values.job_unit,
      industry: values.industry,
    });
    Toast.show({
      icon: "success",
      content: "注册成功",
    });
    setTimeout(() => {
      navigate("/login");
    }, 2000);
  };
  const { name, phone, city, job_unit, industry } =
    JSON.parse(localStorage.getItem("token")) || "";
  return (
    <div>
      <Form
        onFinish={onFinish}
        layout="horizontal"
        footer={
          <Button
            block
            type="submit"
            color="primary"
            size="small"
            style={{
              width: "50%",
              margin: "20px auto",
              borderRadius: "15px",
            }}
          >
            提交
          </Button>
        }
      >
        <Form.Item
          name="username"
          label="用户名"
          rules={[{ required: true, message: "用户名不能为空" }]}
        >
          <Input placeholder="填写您的用户名" />
        </Form.Item>
        <Form.Item
          name="password"
          label="密码"
          rules={[{ required: true, message: "密码不能为空" }]}
        >
          <Input placeholder="填写您的密码" />
        </Form.Item>
        <Form.Item
          name="name"
          label="姓名"
          rules={[{ required: true, message: "姓名不能为空" }]}
        >
          <Input placeholder="填写您的姓名" />
        </Form.Item>
        <Form.Item name="phone" label="手机">
          <Input placeholder="填写您的手机号码" />
        </Form.Item>
        <Form.Item name="city" label="所在城市">
          <Input placeholder="填写您的所在城市" />
        </Form.Item>
        <Form.Item name="job_unit" label="所在单位">
          <Input placeholder="填写您的所在单位" />
        </Form.Item>
        <Form.Item name="industry" label="行业领域">
          <Input placeholder="填写您的行业领域" />
        </Form.Item>
      </Form>
    </div>
  );
}
